package com.ruoyi.course.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.vo.ExamCourseTagVo;
import com.ruoyi.course.service.IExamCourseTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 课程标签Controller
 *
 * @author Tellsea
 * @date 2025-09-25
 */
@Api(tags = "课程标签Controller")
@RestController
@RequestMapping("/course/courseTag")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ExamCourseTagController extends BaseController {

    private final IExamCourseTagService examCourseTagService;

    @ApiOperation("查询课程标签列表")
    @PreAuthorize("@ss.hasPermi('course:courseTag:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamCourseTagVo> list(ExamCourseTagVo entity) {
        return examCourseTagService.queryList(entity);
    }

    @ApiOperation("查询课程标签所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ExamCourseTagVo entity) {
        return AjaxResult.success("查询成功", examCourseTagService.queryAll(entity));
    }

    @ApiOperation("导出课程标签列表")
    @PreAuthorize("@ss.hasPermi('course:courseTag:export')")
    @Log(title = "课程标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamCourseTagVo entity) {
        List<ExamCourseTagVo> list = examCourseTagService.queryAll(entity);
        ExcelUtil<ExamCourseTagVo> util = new ExcelUtil<>(ExamCourseTagVo.class);
        util.exportExcel(response, list, "课程标签数据");
    }

    @ApiOperation("获取课程标签详细信息")
    @PreAuthorize("@ss.hasPermi('course:courseTag:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", examCourseTagService.queryById(id));
    }

    @ApiOperation("新增课程标签")
    @PreAuthorize("@ss.hasPermi('course:courseTag:add')")
    @Log(title = "课程标签", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ExamCourseTagVo entity) {
        return toAjax(examCourseTagService.save(entity));
    }

    @ApiOperation("修改课程标签")
    @PreAuthorize("@ss.hasPermi('course:courseTag:edit')")
    @Log(title = "课程标签", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ExamCourseTagVo entity) {
        return toAjax(examCourseTagService.updateById(entity));
    }

    @ApiOperation("删除课程标签")
    @PreAuthorize("@ss.hasPermi('course:courseTag:remove')")
    @Log(title = "课程标签", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(examCourseTagService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
